/*
 *  Copyright 2013 National Institute of Advanced Industrial Science and Technology
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.sss.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.sss.mapreduce.Encodings;

public class TaskSet {
  private BytesClassLoader classLoader;
  private Map<String, Object> vars = new HashMap<String, Object>();
  private List<UUID> jobs = new ArrayList<UUID>();
  private Encodings encodings;

  public TaskSet() {
    this.classLoader = new BytesClassLoader();
    this.encodings = new Encodings(classLoader);
  }

  public BytesClassLoader getClassLoader() {
    return classLoader;
  }

  public Encodings getEncodings() {
    return encodings;
  }

  public synchronized <T> T get(String key, Class<T> klass) {
    Object v = vars.get(key);
    return (v != null)?klass.cast(v):null;
  }

  public synchronized Object get(String key) {
    return vars.get(key);
  }

  public synchronized void set(String key, Object value) {
    vars.put(key, value);
  }

  public synchronized void addJobID(UUID jobID) {
    if (!jobs.contains(jobID)) {
      jobs.add(jobID);
    }
  }

  public List<UUID> getJobIDList() {
    return jobs;
  }
}
